package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "医院列表API接口")
@RestController
@RequestMapping("/api/hosp/hospital")
//@CrossOrigin
public class ApiHospitalController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("获取医院签名")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo  getSignInfoVo(@PathVariable("hoscode")String hoscode){

      SignInfoVo signInfoVo =  hospitalService.getSignInfoVoByHoscode(hoscode);

        return signInfoVo;
    }


    /**
     * 首页数据分析
     * 1，获取医院等级（根据数据字典编码获取）
     * 2，获取地区（根据数据字典编码获取）
     * 3，医院分页列表
     * 4，根据医院名称关键字搜索医院列表
     */

    @ApiOperation(value = "获取分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result<Page<Hospital>> getHospitalPage(@PathVariable("page") Integer page,
                                                  @PathVariable("limit") Integer limit,
                                                  HospitalQueryVo hospitalQueryVo) {
        // 调用业务层分页查询
        Page<Hospital> hospitalPage = hospitalService.getHospitalPage(page, limit, hospitalQueryVo);
        // 返回数据结果
        return Result.ok(hospitalPage);
    }

    @ApiOperation(value = "根据医院名称关键字搜索医院列表")
    @GetMapping("getHospListByHosName/{hosname}")
    public Result<List<Hospital>> getHospListByHosName(@PathVariable("hosname") String hosname
    ) {
        // 调用业务层分页查询
        List<Hospital> hospitalList = hospitalService.getHospListByHosName(hosname);
        // 返回数据结果
        return Result.ok(hospitalList);
    }

    //需要获取医院信息（医院基本信息、预约信息）和科室信息
    @ApiOperation("根据医院编号查询医院信息")
    @GetMapping("showHospDetailByHoscode/{hoscode}")
    public Result showHospDetailByHoscode(@PathVariable("hoscode") String hoscode) {
        // 调用方法查询
        Map<String, Object> resMap = hospitalService.showHospDetailByHoscode(hoscode);

        return Result.ok(resMap);
    }

    @ApiOperation("根据医院编号查询科室信息")
    @GetMapping("depDetailByHoscode/{hoscode}")
    public Result showDepOfHospByHoscode(@PathVariable("hoscode") String hoscode) {
        // 调用部门查询列表
        List<DepartmentVo> departmentVoList = departmentService.getDepartmentListByHoscode(hoscode);

        return Result.ok(departmentVoList);
    }


}
